package com.zcn.io.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcn.io.common.pojo.CommonResult;
import com.zcn.io.web.api.entity.NegotiateInfo;
import com.zcn.io.web.api.vo.NegotiateInfoVo;
import com.zcn.io.web.service.NegotiationService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 协商任务明细
 * @author: 202438 邱建伟
 * @date: 2025/1/12 11:22
 * @Copyright (c) 2025, 江苏金恒信息科技股份有限公司
 */
@RestController
@AllArgsConstructor
@RequestMapping("/negotiation")
public class NegotiationController {

    private final NegotiationService negotiationService;

    @GetMapping("/list")
    public CommonResult<Page<NegotiateInfo>> list(Page<NegotiateInfo> page, NegotiateInfo negotiateInfo) {
        negotiationService.list(page, negotiateInfo);
        return CommonResult.success(page);
    }

    @PostMapping("/save")
    public CommonResult<NegotiateInfo> save(@RequestBody NegotiateInfo negotiateInfo) {
        negotiationService.save(negotiateInfo);
        return CommonResult.success(negotiateInfo);
    }

    @GetMapping("/getById")
    public CommonResult<NegotiateInfo> getById(@RequestParam String id) {
        return CommonResult.success(negotiationService.getById(id));
    }

    @PostMapping("/updateById")
    public CommonResult<NegotiateInfo> updateById(@RequestBody NegotiateInfo negotiateInfo) {
        negotiationService.updateById(negotiateInfo);
        return CommonResult.success(negotiateInfo);
    }

    @DeleteMapping("/deleteById")
    public CommonResult<String> deleteById( NegotiateInfo negotiateInfo) {
        negotiationService.deleteById(negotiateInfo.getId());
        return CommonResult.success(negotiateInfo.getId());
    }

    @GetMapping("/listAllByPhoneCode")
    public CommonResult<List<NegotiateInfoVo>> listAllByPhoneCode(NegotiateInfo negotiateInfo) {
        return CommonResult.success(negotiationService.listAllByPhoneCode(negotiateInfo));
    }

}
